package io.alvin.ch02;

/**
 * volatile Demo
 * Created by Alvin on 2017/7/6.
 */
public class NoVisibility {

    private static volatile boolean ready;

    private static int number = 0;

    private static class ReaderThread extends Thread {
        @Override
        public void run() {
            while(!ready);
            System.out.println(number);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        new ReaderThread().start();
        Thread.sleep(1000);
        number = 31;
        ready = true;
        Thread.sleep(1000);
    }
}
